package com.example.ten.controller;

import com.aaa.entity.Dept;
import com.aaa.service.DeptService;
import com.aaa.util.Page;
import com.aaa.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: Jyc
 * @classname: DeptController
 * @date: 2023/3/29
 * @time: 14:44
 * @description:
 */
@RestController
@RequestMapping("dept")
public class DeptController extends BaseController {

    @Resource
    private DeptService deptService;


    /**
     * 查询所有启用部门(添加员工时，下拉框使用)
     * @return
     */
    @GetMapping("queryAllDept")
    public Result  queryAllDept(){
        return success(deptService.queryAllDept());
    }
    /**
     * 根据参数查询列表
     * @param page
     * @return
     */
  @PostMapping("queryByParam")
    public Result queryByParam(@RequestBody Page<Dept> page) {
        return success(deptService.queryByParam(page));
    }

    /**
     *  根据编号查询对象
     * @param deptId
     * @return
     */
    @RequestMapping(value = "queryById",method =RequestMethod.GET )
    public Result queryById(@RequestParam(value = "deptNo",required = false,defaultValue ="1" ) Integer deptId) {
        return success(deptService.queryById(deptId));
    }



    /**
     * 添加
     *  参数传递：使用实体传递参数    要求请求的参数名称，必须和实体中的属性名称对应
     * @param dept
     * @return
     */
    @PostMapping("add")
    public Result add(@RequestBody Dept dept) {
        return success(deptService.add(dept));
    }

    /**
     * 更新
     * @param dept
     * @return
     */
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public Result update(@RequestBody  Dept dept) {
        return success(deptService.update(dept));
    }

    /**
     * 根据编号删除对象
     * @param deptId
     * @return
     */
    @DeleteMapping("deleteById") //地址栏无法模拟  会报HTTP状态 405 - 方法不允许
    public Result deleteById(Integer deptId) {
        System.out.println(deptId);
        //执行删除
        return success(deptService.deleteById(deptId));
    }


}
